﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using Einstein.Platform.Window; 
using Einstein.Data;
using Einstein.Utility;
using Einstein.Group.DAL;

namespace Einstein.Platform
{
    public partial class Login : Office2007Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btn_Click(object sender, EventArgs e)
        {
            ButtonX btn = sender as ButtonX;
            if (btn != null)
            {
                if (btn.Name == "btnLogin")
                {
                    if (string.IsNullOrWhiteSpace(txtUserName.Text))
                    {
                        BoxManager.ShowWarning("请填写用户名!");
                        txtUserName.Focus();
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(txtpwd.Text))
                    {
                        BoxManager.ShowWarning("请填写密码!");
                        txtpwd.Focus();
                        return;

                    }

                    Operator info = new OperatorDAL().GetByUserNameAndPwd(new Data.Operator { UserName = txtUserName.Text, Password = txtpwd.Text });

                    if (info == null)
                    {
                        BoxManager.ShowWarning("用户名或密码错误，请重试!");
                        return;
                    }
                    else if (info.ExpireDate < DateTime.Now)
                    {
                        BoxManager.ShowWarning("用户已经过期!");
                        return;
                    }
                    else
                    {
                        GlobalContents.CurrentLoginName = info.ChineseName;
                        this.DialogResult = DialogResult.OK;
                    }

                }
                this.Close();
            }
        }
    }
}
